package cn.zch.soft.util.ftp.gitxlxl2010.run;
import cn.zch.soft.util.ftp.gitxlxl2010.bussiness.BussinessUtil;
import cn.zch.soft.util.ftp.gitxlxl2010.quartz.FtpQuartz;
import cn.zch.soft.util.ftp.gitxlxl2010.com.util.ConfigConst;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.text.ParseException;
/**
 * 支持断点续传的FTP实用类
 *
 * @author xiongl
 * @version 0.3 实现中文目录创建及中文文件创建，添加对于中文的支持
 */
public class GetWhiteListtask implements Runnable {
  private BussinessUtil bussinessUtil;
  public GetWhiteListtask(BussinessUtil bussinessUtil) {
    super();
    this.bussinessUtil = bussinessUtil;
  }
  @Override
  public void run() {
    try {
      String[] data = (ConfigConst.rundate).split("-");
      String rundate = null;
      if (data.length == 1) {
        rundate = "0 " + "*/" + data[0] + " * * * ?";
      }
      else {
        if (data[0].equals("*")) {
          rundate = "0 " + data[2] + " " + data[1] + " * * ?";
        }
        else {
          rundate = "0 " + data[2] + " " + data[1] + " " + data[0] + " * ?";
        }
      }
      FtpQuartz quartz = new FtpQuartz();
      SchedulerFactory sf = new StdSchedulerFactory();
      String JOB_GROUP_NAME = "group1";
      String TRIGGER_GROUP_NAME = "trigger1";
      String jobName = "11";
      Scheduler sched = sf.getScheduler();
      // 任务名，任务组，任务执行类
      JobDetail jobDetail = new JobDetail(jobName, JOB_GROUP_NAME, quartz.getClass());
      jobDetail.getJobDataMap().put("myjob", bussinessUtil);
      // 触发器 // 触发器名,触发器组
      CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);
      trigger.setCronExpression(rundate);
      // 触发器时间设定
      sched.scheduleJob(jobDetail, trigger);
      // 启动
      if (!sched.isShutdown()) {
        sched.start();
      }
    }
    catch (ParseException | SchedulerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}
